import pyOsi

theSI = pyOsi.getOsi("CBC")

#Read in an mps file.  This one's from the MIPLIB library.
#si->readMps("../../Data/Sample/p0033");
theSI.readMps("p0033")

print "Colums: %d" % theSI.getNumCols() 
print "Rows: %d" % theSI.getNumRows() 

mat_c = theSI.getMatrixByCol()
print "mat_c size: %d" % len(mat_c) 
print mat_c

mat_r = theSI.getMatrixByRow()
print "mat_r size: %d" % len(mat_r) 

print mat_r

theSI.initialSolve()

#Check the solution
if ( theSI.isProvenOptimal() ):
      print "Found optimal solution!" 
      print "Objective value is %f" % theSI.getObjValue()
      n = theSI.getNumCols()
      solution = theSI.getColSolution()
	      
else: 
      print "Didn't find optimal solution."


(values,ind) = theSI.getMatrixByCol()[1]
temp = pyOsi.Int_array(1)
for i,v in enumerate(solution):
    if not v == 0:
	  temp[0] = i
	  break

lb = theSI.getColLower()[temp[0]]
ub = theSI.getColUpper()[temp[0]]
obj = theSI.getObjCoefficients()[temp[0]]
theSI.deleteCols(1,temp)

print "Colums: %d" % theSI.getNumCols() 
print "Rows: %d" % theSI.getNumRows() 

new_ind = pyOsi.Int_array(len(ind))
new_values = pyOsi.Double_array(len(values))
for i,x in enumerate(ind):
	new_ind[i] = x
for i,x in enumerate(values):
	new_values[i] = x

theSI.addCol(len(ind),new_ind,new_values,lb,ub,obj)

print "Colums: %d" % theSI.getNumCols() 
print "Rows: %d" % theSI.getNumRows() 


theSI.resolve()
#Check the solution
if ( theSI.isProvenOptimal() ):
      print "Found optimal solution!" 
      print "Objective value is %f" % theSI.getObjValue()
      n = theSI.getNumCols()
      solution = theSI.getColSolution()
      for i in solution:
            print i
      
else: 
      print "Didn't find optimal solution."

